package com.yanqu.road.server.cmd.union.cross.trade;

import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.pb.union.UnionTradeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;

@Cmd(code = Protocol.S_UNION_TRADE_ROUTE_PATRONS_SEDN_FROM_CROSS, desc = "(加入路线)门客派遣")
public class PatronsSendCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {


        UnionTradeProto.PatronsSendCrossRespMsg respMsg = UnionTradeProto.PatronsSendCrossRespMsg.parseFrom(packet.getBytes());

        //标记门客已派遣
        Map<Integer, UserPatrons> userPatronsMap = player.getModule(PatronsModule.class).getUserPatronsMap();
        for(Integer patronsId : respMsg.getPatronsIdList()){
            userPatronsMap.get(patronsId).setUnionTradeSend(true);
        }

        DataAnalyticsMgr.trackOreWarJoinRoad(player, respMsg.getRouteId());

        UnionTradeProto.PatronsSendRespMsg.Builder clientMsg = UnionTradeProto.PatronsSendRespMsg.newBuilder();
        clientMsg.setRet(respMsg.getRet());
        player.sendPacket(Protocol.U_UNION_TRADE_ROUTE_PATRONS_SEDN, clientMsg);

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
